package com.jghz.framework.utils;

import java.io.InputStream;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PropertyHelper
{
	private static Logger logger = LoggerFactory.getLogger(PropertyHelper.class);
	private Properties properties = new Properties();

	public void load(String fileName)
	{
		this.properties.clear();
		ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
		if (classLoader == null)
		{
			classLoader = PropertyHelper.class.getClassLoader();
		}
		try
		{
			InputStream is = classLoader.getResourceAsStream(fileName);
			this.properties.load(is);
		} catch (Exception e1)
		{
			logger.error("加载属性文件" + fileName + "出错!", e1);
			// e1.printStackTrace();
		}
	}

	public String getProperty(String propertyName)
	{
		return this.properties.getProperty(propertyName);
	}

	public String getValue(String key, String defaultValue)
	{
		return this.properties.getProperty(key, defaultValue);
	}

	public void removeProperty(String key)
	{
		this.properties.remove(key);
	}

	public void setProperty(String key, String value)
	{
		this.properties.setProperty(key, value);
	}
}